﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="register.aspx.cs" Inherits="Donal.Xms.Web.temp.main.register" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>注册</title>
    <link href="/scripts/artdialog/ui-dialog.css" rel="stylesheet" />
    <script src="/scripts/jquery/jquery-1.11.2.min.js"></script>
    <script src="/scripts/jquery/jquery.cookie.js"></script>
    <script src="/scripts/artdialog/dialog-min.js"></script>
    <script src="/scripts/jquery/common.js"></script>
    <script>
        $(function () {
            let isRun = 0;

            $("#btnOK").click(function () {

                if (!$("#agreement").prop('checked')) {
                    dialog({
                        title: "提示",
                        content: "请先同意相关服务协议！",
                        okValue: '确定',
                        ok: function () { }
                    }).showModal();
                    return;
                }

                var mobile = $("#txtMobile").val().trim();
                var sms = $("#txtSms").val().trim();

                if (mobile == "") {
                    dialog({
                        title: "提示",
                        content: "请输入手机号！",
                        okValue: '确定',
                        ok: function () { }
                    }).showModal();
                    return;
                } else {
                    var reg = new RegExp(/^1\d{10}$/g);
                    if (!reg.test(mobile)) {

                        dialog({
                            title: "提示",
                            content: "请输入正确的手机号！",
                            okValue: '确定',
                            ok: function () { }
                        }).showModal();
                        return;
                    }
                }

                if (sms == "") {
                    dialog({
                        title: "提示",
                        content: "请输入手机验证码！",
                        okValue: '确定',
                        ok: function () { }
                    }).showModal();
                    return;
                }

                if (sms != "" && sms.length != 5) {
                    dialog({
                        title: "提示",
                        content: "请输入正确的手机验证码！",
                        okValue: '确定',
                        ok: function () { }
                    }).showModal();
                    return;
                }

                if (isRun == 0) {
                    isRun = 1;
                    $.ajax({
                        type: "post",
                        url: "/tools/submit_ajax.ashx?action=user_register_" + new Date().getTime(),
                        data: { sms, mobile },
                        dataType: "json",
                        success: function (data) {
                            isRun = 0;
                            dialog({
                                title: "提示",
                                content: data.msg,
                                okValue: '确定',
                                ok: function () { }
                            }).showModal();

                            if (data.status == 1) {
                                window.location.href = '/user/center.html';
                            }
                        }
                    });
                }

            })
        })

        function smsCode(obj) {
            let reg = new RegExp(/^\d{11}$/g);
            let code = $("#txtCode").val();
            let txtMobile = $("#txtMobile").val();

            if (!reg.test(txtMobile)) {
                dialog({
                    title: "提示",
                    content: "请输入正确的手机号！",
                    okValue: '确定',
                    ok: function () { }
                }).showModal();
                return;
            }

            if (code == "") {
                dialog({
                    title: "提示",
                    content: "请输入验证码！",
                    okValue: '确定',
                    ok: function () { }
                }).showModal();
                return;
            }

            if (code != "" && code.length != 4) {
                dialog({
                    title: "提示",
                    content: "请输入正确的验证码！",
                    okValue: '确定',
                    ok: function () { }
                }).showModal();
                return;
            }

            if ($.cookie("smstime") == "" || $.cookie("smstime") == null) {
                var url = "/tools/submit_ajax.ashx?action=user_verify_smscode_" + new Date().getTime();
                sendSMS(obj, txtMobile, url, code);

            } else {
                if (parseFloat(new Date().getTime()) - parseFloat($.cookie("smstime")) > <%= base.uconfig.regsmsexpired*60000 %>) {
                    var url = "/tools/submit_ajax.ashx?action=user_verify_smscode_" + new Date().getTime();
                    sendSMS(obj, txtMobile, url, code);
                } else {
                    dialog({
                        title: "提示",
                        content: "您的验证请求太频了，请休息一会吧！\n（发送间隔为 " +<%= base.uconfig.regsmsexpired %>+" 分钟）",
                        okValue: '确定',
                        ok: function () { }
                    }).showModal();
                    return;
                }
            }
        };
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <input id="agreement" name="agreement" type="checkbox" /><label for="agreement"></label>
            <input type="tel" placeholder="请输入手机号码" id="txtMobile" />
            <input type="tel" inputmode="numeric" placeholder="验证码" id="txtCode" />
            <img src="/tools/verify_code.ashx" onclick="imgToggleCode(this, '/tools/verify_code.ashx');return false;" id="imgReg" />
            <input type="tel" inputmode="numeric" placeholder="手机验证码" id="txtSms" maxlength="5" />
            <input type="button" value="发送验证码" onclick="smsCode(this);" />
            <input type="button" value="注册" id="btnOK" />
        </div>
    </form>
</body>
</html>
